using Extensions;

namespace _ReplaceString_.UI.Styles;
public abstract record UISize() : UIStyle(false, false)
{
	public static UISize FixedHeight(float height) => new FixedHeight(height);
	public static UISize FixedWidth(float width) => new FixedWidth(width);
	public static UISize Fill { get; } = new Fill();
	public static UISize FlexibleHeight { get; } = new FlexibleHeight();
	public static UISize FlexibleWidth { get; } = new FlexibleWidth();
	public static UISize TransformMargin(float margin, Direction direction) => new Margin(margin, direction);

}
file record FixedHeight(float Height) : UISize
{
	public override void Apply(UIBase ui)
	{
		ui.MaxHeight = ui.Height = new(Height, 0);
		ui.Tag |= UITag.FixedHeight;
	}
}
file record FixedWidth(float Width) : UISize
{
	public override void Apply(UIBase ui)
	{
		ui.MaxWidth = ui.Width = new(Width, 0);
		ui.Tag |= UITag.FixedWidth;
	}
}

file record Fill : UISize
{
	public override void Apply(UIBase ui)
	{
		ui.Width = new(0, 1);
		ui.Height = new(0, 1);
	}
}

file record FlexibleHeight : UISize
{
	public override void Apply(UIBase ui)
	{
		ui.Height = new(0, 0);
		ui.Tag |= UITag.FlexibleHeight;
	}
}

file record FlexibleWidth : UISize
{
	public override void Apply(UIBase ui)
	{
		ui.Width = new(0, 0);
		ui.Tag |= UITag.FlexibleWidth;
	}
}

file record Margin(float Value, Direction Direction) : UISize
{
	public override void Apply(UIBase ui)
	{
		if(Direction.Has(Direction.Left))
		{
			ui.MarginLeft += Value;
			ui.Width.Pixels -= Value;
		}
		if (Direction.Has(Direction.Right))
		{
			ui.MarginRight += Value;
			ui.Width.Pixels -= Value;
		}
		if (Direction.Has(Direction.Up))
		{
			ui.MarginTop += Value;
			ui.Height.Pixels -= Value;
		}
		if (Direction.Has(Direction.Down))
		{
			ui.MarginBottom += Value;
			ui.Height.Pixels -= Value;
		}
	}
}